<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div>我是一个粉刷匠</div>
    <div>我是一个粉刷匠</div>
    <div>我是一个粉刷匠</div>
    <div>我是一个粉刷匠</div>
    <div>我是一个粉刷匠</div>
    <script>
        (function (window, undefined) {
            var jQuery = function (selector) {
                return new jQuery.fn.init(selector);
            }
            //原型替换
            jQuery.fn = jQuery.prototype = {
                constructor: jQuery,
                init: function (selector) {
                    var elements = document.querySelectorAll(selector);
                    [].push.apply(this, elements);
                },
                css: function (name, value) {
                    console.log(name,value)
                    // 
                    if (arguments.length === 2) {
                        for (var i = 0; i < this.length; i++) {
                            console.log(this[i])
                            this[i].style[name] = value
                        }
                    }
                },
                
                html: function () {
                    console.log("html is bad")
                }
            }
            //修改init的原型对象为jQuery原型对象 
            jQuery.fn.init.prototype = jQuery.fn;
            window.jQuery = window.$ = jQuery;
        })(window)
        var $divs = $("div");
        console.log($divs);
        $divs.css("color", "red");
            // $divs.html();


    </script>
</body>

</html>